//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "ExtOUWithJumpsProcess.h"
using namespace Cephei::QL::Experimental::Processes;
#include <gen/QL/Math/Array.h>
#include <gen/QL/Experimental/Processes/ExtendedOrnsteinUhlenbeckProcess.h>
#include <gen/QL/StochasticProcess.h>
using namespace Cephei::QL::Math;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (Cephei::QL::Experimental::Processes::IExtendedOrnsteinUhlenbeckProcess^ process, Double Y0, Double beta, Double jumpIntensity, Double eta) : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
    CExtendedOrnsteinUhlenbeckProcess^ _Cprocess;
    try
    {
#ifdef HANDLE
        _phExtOUWithJumpsProcess = NULL;
#endif
        _Cprocess = safe_cast<CExtendedOrnsteinUhlenbeckProcess^> (process);
        _Cprocess->Lock();
        boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess>& _process = static_cast<boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess>&> (_Cprocess->GetShared ()); 
        QuantLib::Real _Y0 = (QuantLib::Real)ValueHelper::Convert (Y0); //d
        QuantLib::Real _beta = (QuantLib::Real)ValueHelper::Convert (beta); //d
        QuantLib::Real _jumpIntensity = (QuantLib::Real)ValueHelper::Convert (jumpIntensity); //d
        QuantLib::Real _eta = (QuantLib::Real)ValueHelper::Convert (eta); //d
        _ppExtOUWithJumpsProcess = new boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess> (new QuantLib::ExtOUWithJumpsProcess ( _process,  _Y0,  _beta,  _jumpIntensity,  _eta ));
        SetStochasticProcess (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppExtOUWithJumpsProcess));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cprocess != nullptr) _Cprocess->Unlock();
    }
}
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess>& childNative, Object^ owner) : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
#ifdef HANDLE
	_phExtOUWithJumpsProcess = NULL;
#endif
	_ppExtOUWithJumpsProcess = &childNative;
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppExtOUWithJumpsProcess));
}
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (QuantLib::ExtOUWithJumpsProcess& childNative, Object^ owner) : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
#ifdef HANDLE
	_phExtOUWithJumpsProcess = NULL;
#endif
	_ppExtOUWithJumpsProcess = new boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess> (&childNative);
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppExtOUWithJumpsProcess));
    _ExtOUWithJumpsProcessOwner = owner;
    _StochasticProcessOwner = owner;
}

Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (CExtOUWithJumpsProcess^ copy) : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
#ifdef HANDLE
	_phExtOUWithJumpsProcess = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppExtOUWithJumpsProcess = new boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess> (copy->GetShared());
        _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppExtOUWithJumpsProcess));
    }
}
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (PLATFORM::Type^ t) : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
#ifdef HANDLE
	_phExtOUWithJumpsProcess = NULL;
#endif
	if (!t->IsSubclassOf(CExtOUWithJumpsProcess::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (QuantLib::Handle<QuantLib::ExtOUWithJumpsProcess>& childNative, Object^ owner)  : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
	_phExtOUWithJumpsProcess = &childNative;
	_ppExtOUWithJumpsProcess = &static_cast<boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess>>(childNative.currentLink());
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppExtOUWithJumpsProcess));
    _ExtOUWithJumpsProcessOwner = owner;
}
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (QuantLib::Handle<QuantLib::ExtOUWithJumpsProcess> childNative)  : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
	_phExtOUWithJumpsProcess = &childNative;
	_ppExtOUWithJumpsProcess = &static_cast<boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess>>(childNative.currentLink());
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppExtOUWithJumpsProcess));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::CExtOUWithJumpsProcess (QuantLib::ExtOUWithJumpsProcess childNative)  : CStochasticProcess(CExtOUWithJumpsProcess::typeid)
{
#ifdef HANDLE
	_phExtOUWithJumpsProcess = NULL;
#endif
	_ppExtOUWithJumpsProcess = new boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess> (new QuantLib::ExtOUWithJumpsProcess (childNative));
    _ppStochasticProcess = new boost::shared_ptr<QuantLib::StochasticProcess> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppExtOUWithJumpsProcess));
}
#endif

Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::~CExtOUWithJumpsProcess ()
{
    if (_ppExtOUWithJumpsProcess != NULL)
    {
	    delete _ppExtOUWithJumpsProcess;
        _ppExtOUWithJumpsProcess = NULL;
    }
}
Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::!CExtOUWithJumpsProcess ()
{
    if (_ppExtOUWithJumpsProcess != NULL)
    {
	    delete _ppExtOUWithJumpsProcess;
    }
}
QuantLib::ExtOUWithJumpsProcess& Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::GetReference ()
{
    if (_ppExtOUWithJumpsProcess == NULL) throw REFNEW NativeNullException ();
	return **_ppExtOUWithJumpsProcess;
}
boost::shared_ptr<QuantLib::ExtOUWithJumpsProcess>& Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::GetShared ()
{
    if (_ppExtOUWithJumpsProcess == NULL) throw REFNEW NativeNullException ();
	return *_ppExtOUWithJumpsProcess;
}
QuantLib::ExtOUWithJumpsProcess* Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::GetPointer ()
{
    if (_ppExtOUWithJumpsProcess == NULL) throw REFNEW NativeNullException ();
	return &**_ppExtOUWithJumpsProcess;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ExtOUWithJumpsProcess>& Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::GetHandle ()
{
	if (_phExtOUWithJumpsProcess == NULL)
	{
		_phExtOUWithJumpsProcess = new Handle<QuantLib::ExtOUWithJumpsProcess> (*_ppExtOUWithJumpsProcess);
	}
	return *_phExtOUWithJumpsProcess;
}
#endif
bool Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::HasNative () 
{
	return (_ppExtOUWithJumpsProcess != NULL);
}

Double Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::Beta::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtOUWithJumpsProcess)->beta ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::Eta::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtOUWithJumpsProcess)->eta ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::Factors::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppExtOUWithJumpsProcess)->factors ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Processes::IExtendedOrnsteinUhlenbeckProcess^ Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::GetExtendedOrnsteinUhlenbeckProcess::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess> _rv = (boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess>)(*_ppExtOUWithJumpsProcess)->getExtendedOrnsteinUhlenbeckProcess ( );   
        Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess^ _nrv = REFNEW Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::JumpIntensity::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtOUWithJumpsProcess)->jumpIntensity ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess::Size::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppExtOUWithJumpsProcess)->size ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Processes::IExtOUWithJumpsProcess^ Cephei::QL::Experimental::Processes::CExtOUWithJumpsProcess_Factory::Create (Cephei::QL::Experimental::Processes::IExtendedOrnsteinUhlenbeckProcess^ process, Double Y0, Double beta, Double jumpIntensity, Double eta)
{
    return REFNEW CExtOUWithJumpsProcess ( process,  Y0,  beta,  jumpIntensity,  eta);
}
